var t = require("../../../mycomponent/yz_pay/yz_pay"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        isclick: !0,
        order_id: "",
        store_id: "",
        orderData: null,
        balance: 0,
        payParams: "",
        info_form: {},
        order_sn: "",
        money: "",
        buttons: [],
        pay_sn: "订单编号",
        order_pay_id: "",
        uid: "",
        pid: "",
        status: "",
        showPacket: !1,
        redirectData: {},
        cbHref: {},
        is_cps: !1,
        senceKey: "",
        payTag: "",
        kefuPopShow: false,//联系客服弹窗
    },
     // 联系客服取消按钮
     hideModal(){
      this.setData({
        kefuPopShow: false
      })
    },
    fromChild: function(t) {
      console.log(t,'fromChildfromChildfromChild',this.data.balance,this.data.money)
      // if(Number(this.data.balance) < Number(this.data.money)){
      //   this.setData({
      //     kefuPopShow: true
      //   })
      //   return
      // }
        if (console.log(t), "0.00" == this.data.money) {
            if ("auth" == this.data.tag) return void this.authPay("54");
            this.sureBtn();
        }else if(Number(this.data.balance) < Number(this.data.money)){
          this.setData({
            kefuPopShow: true
          })
          return
        } else {
            var a = t.detail.submitArr;
            if (console.log(a, "ddddddddddd"), "auth" == this.data.tag) return void this.authPay(a.value);
            if ("tourAround" == this.data.tag) return void (a.need_password ? this.rechargePay(a.value, this.data.order_sn, this.data.order_sn, "tourAroundPay", a) : (console.log("111111111"), 
            this.ordinary(this.data.order_sn, a.value, a)));
            this.confirm(a);
        }
    },
    ordinary: function(t, e, o) {
        var s = this, n = {
            order_sn: t,
            pay_type: e
        }, r = a.getNetAddresss("plugin.travel-around.frontend.payment.payment.pay");
        a._getNetWork({
            url: r,
            data: n,
            success: function(a) {
                1 == a.data.result ? (console.log("111111123423"), s.rechargePay(e, a.data, t, "tourAroundPay", o)) : (wx.showToast({
                    title: a.data.msg,
                    icon: "success",
                    duration: 2e3
                }), console.log("错误", a.data.msg));
            }
        });
    },
    onClickHide: function() {
        this.setData({
            showPacket: !1
        }), this.toRedirect();
    },
    toPacket: function() {
        wx.redirectTo({
            url: "/packageE/ConsumePacket/ConsumePacketSuccess/ConsumePacketSuccess?order_id=" + this.data.order_id.toString()
        });
    },
    confirm: function(t) {
        console.log(t,'confirm');
        var a = t.value, e = t;
        this.handlePay(e, a);
    },
    onLoad: function(t) {
        var a, e, o = wx.getEnterOptionsSync();
        if (this.setData({
            senceKey: o.scene
        }), console.log("options:", t), t.iscps && (this.data.is_cps = !0), t.name && this.setData({
            name: t.name
        }), t.pid && this.setData({
            pid: t.pid
        }), t.tag && this.setData({
            tag: t.tag
        }), this.setData({
            order_id: t.order_id
        }), t.status && this.setData({
            status: t.status
        }), t.store_id && this.setData({
            store_id: t.store_id
        }), "auth" == t.tag) return this.setData({
            money: t.price,
            tag: "auth"
        }), void this.authPayButton();
        if ("tourAround" == t.tag) return this.setData({
            order_sn: t.ordersn,
            payTag: t.tag
        }), console.log("11111111"), void this.tourAroundOrder(t.api);
        var s = wx.getStorageSync("yz_basic_info");
        1 == (null == s || null === (a = s.globalParameter) || void 0 === a ? void 0 : a.is_open_shop_esign_v2) ? this.getShopSignV2() : 1 == (null == s || null === (e = s.globalParameter) || void 0 === e ? void 0 : e.is_open_shop_esign) ? this.getShopSign() : setTimeout(()=>{this.getMultipleOrderInfo()},1000);
    },
    getMultipleOrderInfo: function() {
        var t = this, e = null;
        e = this.options.api && "order.operation.pay" != this.options.api ? a.getNetAddresss(this.options.api) : a.getNetAddresss("order.merge-pay"), 
        this.options.status && 2 == this.options.status ? "string" == typeof this.options.order_id ? e += "&order_ids=" + this.options.order_id : e += "&order_ids=" + JSON.parse(this.options.order_id).toString() : e += "&order_ids=" + this.options.order_id, 
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data.data;
                console.log("PayResult::::", e), 1 == a.data.result ? (t.hanleIcon(e), t.setData({
                    order_sn: e.order_pay.pay_sn,
                    balance: e.member.credit2,
                    money: e.order_pay.amount.toFixed(2),
                    uid: e.order_pay.uid,
                    buttons: e.buttons,
                    min_url: e.min_redirect_url
                }), t.data.order_pay_id = e.order_pay.id, t.data.buttons && 0 == t.data.buttons.length && wx.showToast({
                    title: "平台未开启任何支付方式，请联系客服",
                    icon: "none"
                })) : (wx.showToast({
                    title: a.data.msg,
                    icon: "success",
                    duration: 2e3
                }), console.log("错误", a.data.msg));
            }
        });
    },
    getShopSign: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.shop-esign.frontend.contract.get-order-contract"),
            data: {
                order_ids: this.options.order_id
            },
            success: function(a) {
                var e = a.data;
                if (1 == a.data.result) {
                    var o = !1;
                    e.data.map(function(t) {
                        1 === t.need_sign && t.contract_id && !o && (o = !0, wx.showModal({
                            title: "提示",
                            content: "您的订单(订单号:".concat(t.order_sn, ")在支付前需要签署电子合同"),
                            showCancel: !1,
                            success: function(a) {
                                a.confirm && wx.navigateTo({
                                    url: "/packageH/signPage/signPage?id=".concat(t.contract_id, "&fromOrder=1")
                                });
                            }
                        }));
                    }), o || t.getMultipleOrderInfo();
                } else t.getMultipleOrderInfo();
            }
        });
    },
    getShopSignV2: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.shop-esign-v2.frontend.controllers.index.needSign"),
            data: {
                order_id: this.options.order_id
            },
            success: function(a) {
                var e = a.data;
                if (1 == a.data.result) {
                    if (e.data.need_sign) return void wx.showModal({
                        title: "提示",
                        content: "您的订单在支付前需要签署电子合同",
                        showCancel: !1,
                        success: function(a) {
                            a.confirm && wx.navigateTo({
                                url: "/packageH/sign_shopV2/index/index?scene=1&order_id=".concat(t.options.order_id)
                            });
                        }
                    });
                    t.getMultipleOrderInfo();
                } else t.getMultipleOrderInfo();
            }
        });
    },
    authPay: function(t) {
        var e = this, o = a.getNetAddresss("plugin.real-name-auth.frontend.pay.pay");
        a._getNetWork({
            url: o,
            data: {
                pay_id: t,
                pay_amount: this.data.money,
                pay_sn: this.data.order_sn
            },
            success: function(a) {
                if (1 == a.data.result) {
                    if ("54" == t) return void wx.navigateBack({
                        delta: 1
                    });
                    wx.showToast({
                        title: a.data.msg,
                        icon: "none",
                        duration: 1e3,
                        success: function(o) {
                            e.rechargePay(t, a.data, a.data.data.pay_sn);
                        }
                    });
                } else wx.showToast({
                    title: a.data.msg,
                    icon: "success",
                    duration: 2e3
                }), console.log("错误", a.data.msg);
            }
        });
    },
    tourAroundOrder: function(t) {
        var e = this;
        console.log(t);
        var o = {
            order_sn: this.data.order_sn
        };
        console.log(o);
        var s = a.getNetAddresss(t);
        a._getNetWork({
            url: s,
            data: o,
            success: function(t) {
                var a, o, s, n, r = t.data.data;
                1 == t.data.result ? (console.log("执行"), console.log(r), e.setData({
                    order_sn: null === (a = r.order) || void 0 === a ? void 0 : a.order_sn,
                    balance: null == r ? void 0 : r.credit2,
                    money: null === (o = r.order) || void 0 === o ? void 0 : o.order_price,
                    uid: null === (s = r.order) || void 0 === s ? void 0 : s.id,
                    buttons: r.buttons,
                    order_pay_id: null === (n = r.order) || void 0 === n ? void 0 : n.id
                }), console.log(e.data.buttons)) : (wx.showToast({
                    title: t.data.msg,
                    icon: "success",
                    duration: 2e3
                }), console.log("错误", t.data.msg));
            }
        });
    },
    authPayButton: function() {
        var t = this, e = a.getNetAddresss("plugin.real-name-auth.frontend.pay.getPayButton");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data.data;
                1 == a.data.result ? (console.log(e, "ddddddddddd"), t.hanleIcon(e), t.setData({
                    order_sn: e.pay_sn,
                    buttons: e.buttons
                })) : (wx.showToast({
                    title: a.data.msg,
                    icon: "success",
                    duration: 2e3
                }), console.log("错误", a.data.msg));
            }
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {
        this.data.isPayClick = !1;
    },
    onUnload: function() {
        "activity" == this.data.tag && wx.navigateBack({
            delta: 1
        }), "Myshaky" == this.data.name && wx.navigateBack({
            delta: 1
        });
    }
});